/**
* @description: 标准化作业--会商分配
* @author: wqn
* @data:2023年6月19日
* @remark:
**/
<template>
	<view class="allocation">
		<nav-bar title="会商分配" @goBack="goBack"></nav-bar>
		<view class="info">
			<van-form ref="ruleForm">
				<van-field v-model="distributionData.discussersNmae" readonly required label="会商人员"
					:rules="[{ required: true, trigger:'onSubmit'}]" placeholder="请选泽" input-align="right"
					right-icon="arrow" @click-right-icon="handleSelectUser" />
				<van-field v-model="distributionData.consultationTime" readonly required label="会商时间"
					:rules="[{ required: true, trigger:'onSubmit'}]" placeholder="请选泽" input-align="right"
					right-icon="arrow" @click-right-icon="showDate = true" />
				<van-field v-model="distributionData.consultationAddress" required label="会商地点" placeholder="请输入"
					:rules="[{ required: true, trigger:'onSubmit'}]" input-align="right" />
			</van-form>
			<!--    提交按钮-->
			<view class="verify">
				<van-button type="info" round @click="affirmClick">确认</van-button>
			</view>

			<!--    时间选择器-->
			<van-popup v-model="showDate" round position="bottom">
				<van-datetime-picker v-model="currentDate" type="datetime" title="选择时间"
					@confirm="selectTime(currentDate)" :min-date="minDate" />
			</van-popup>
			<!--选择人员-->
			<van-popup v-model="showSelectUser" position="right">
				<selectUser :equIds="equIds" :selected.sync="staffList" @cancel="showSelectUser = false"
					:roleId="executiveRoleId" @comfirm="userComfirm"/>
			</van-popup>
		</view>
	</view>
</template>

<script>
	import navBar from "../common/navBar.vue"
	import selectUser from "../../standardizedOperation/common/selectUser.vue"
	import moment from "moment/moment";
	import {
		Dialog,
		Toast
	} from "vant";
	import {
		mapGetters
	} from "vuex";

	export default {
		name: "consultationAllocation",
		components: {
			navBar,
			selectUser
		},
		data() {
			return {
				distributionData: {
					workPlanId: '',
					consultationDeductionId: '',
					consultationTime: '',
					consultationAddress: '',
					consultationAssignedld: '',
					consultationAssignedName: '',
					discussers1: "",
					discussersNmae: ""
				},
				showDate: false,
				showSelectUser: false, //人员选择
				equIds: [], //人员id
				staffList: {}, //选择人员数据
				executiveRoleId: "",
				currentDate: new Date(),
				minDate:new Date(),
			}
		},
		computed: {
			...mapGetters(["userData"])
		},
		onLoad(option) {
			this.work = JSON.parse(option.message)
			this.distributionData.workPlanId = this.work.id
			this.distributionData.consultationDeductionId = this.work.objId
		},
		onShow() {
			this.distributionData.consultationAssignedld = this.userData.userId
			this.distributionData.consultationAssignedName = this.userData.userName
		},
		methods: {
			goBack() {
				uni.navigateBack()
			},
			selectTime(currentDate) {
				let timeString = "";
				timeString = moment(currentDate).format('YYYY-MM-DD HH:mm')
				this.distributionData.consultationTime = timeString
				this.showDate = false
			},
			/**
			 * 通知上一个页面刷新数据
			 */
			back() {
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2]; //上一个页面
				prevPage.isRefresh = true
				uni.navigateBack()
			},
			// 提交-按钮
			async affirmClick() {
				await this.$refs.ruleForm
					.validate()
					.then(() => {
						Dialog.confirm({
							message: '是否确认提交？',
							confirmButtonColor: '#417adc'
						}).then(() => {
							this.$apiRequest.bzhzyApi.allocation(this.distributionData).then(res => {
								this.clearParam()
								Toast(res.msg);
								this.back()
							}).catch(error => {
								Toast("提交失败");
							})
						})

					})
					.catch((error) => {

						Toast('请完善内容')
					})
			},
			/**
			 * 清除数据
			 */
			clearParam() {
				this.distributionData = {
					workPlanId: '',
					consultationDeductionId: '',
					consultationTime: '',
					consultationAddress: '',
					consultationAssignedld: '',
					consultationAssignedName: '',
					consultationAssignedTime: '',
					discussers1: "",
					discussersNmae: ""
				}
				this.staffList = {} //人员数据
			},
			/**
			 * 工作负责人选择
			 */
			userComfirm() {
				console.log(this.staffList)
				this.showSelectUser = false
				this.distributionData.discussersNmae = this.staffList.text
				this.distributionData.discussers1 = this.staffList.ids.join()
			},
			handleSelectUser() {
				this.showSelectUser = true
			},
			// getAllocation()
		}
	}
</script>

<style lang="scss" scoped>
	.allocation {
		width: 100vw;
		height: 100vh;
		background: #F2F6FA;

		.info {
			margin: px2vh(30);

			.top-list {
				margin-bottom: px2vh(30);
			}

			.verify {
				.van-button--normal {
					width: calc(100% - #{px2vw(60)});
					height: px2vh(120);
					font-size: px2vh(46);
					background: #417ADC;
					border: 1px solid #417ADC;
					position: absolute;
					bottom: px2vh(60);
					left: px2vw(30);
				}
			}
		}

	}
</style>
